//
//  KLAddGoodViewController.m
//  KunLun
//
//  Created by Mac on 2017/11/29.
//  Copyright © 2017年 stoneobs@icloud.com. All rights reserved.
//

#import "KLNewYunJiaSuSendViewController.h"
#import "KLTextFiledControl.h"
#import "STLocationManger.h"
#import "STTextView.h"
@interface KLNewYunJiaSuSendViewController ()<KLImageScrollViewDelegate>
@property(nonatomic, strong) NSArray<STTableEasyModel*>                     *datasouce;
@property(nonatomic, strong) UITextField                            *detailAddressTextFiled;
@property(nonatomic, strong) KLTextFiledControl                     *priceDayTextFiled;
@property(nonatomic, strong) KLTextFiledControl                     *priceMonthTextFiled;
@property(nonatomic, strong) KLTextFiledControl                     *numPeopleTextFiled;


@property(nonatomic, strong) KLPriceFiledControl                     *priceControl;
@property(nonatomic, strong) KLPriceFiledControl                     *zhekouControl;
@property(nonatomic, strong) STButton                                *tejiaButton;//是否需要特价
@property(nonatomic, strong) STButton                                *baoyouButton;//是否需要特价
@property(nonatomic, strong) STButton                                *tejiaBeginButton;//特价开始
@property(nonatomic, strong) STButton                                *tejiaEndButton;//特价结束
@property(nonatomic, strong) STButton                                *tejiaZheKouButton;//特价结束
//banner
@property(nonatomic, strong) KLImageScrollView                     *bannerScrollView;
@property(nonatomic, strong) NSArray                     *imageUrlsArray;
//详细三张
@property(nonatomic, strong) KLImageScrollView                     *detailScrollView;
@property(nonatomic, strong) NSArray                     *detailImageUrlsArray;

@property(nonatomic, strong) NSString                     *zhekoulv;
@end

@implementation KLNewYunJiaSuSendViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.zhekoulv = @"8";
    if (self.goodModel) {
        self.zhekoulv = @(self.goodModel.bargain_price.integerValue/10).description;
    }
    self.title = self.model.classify_id;
    if (self.goodModel.classification.integerValue == 3) {
       self.title = @"匀加速市场";
    }
    if (self.goodModel.classification.integerValue == 1) {
        self.title = @"各地特产";
    }
    [self configSubView];
    [self configDataSouce];
    // Do any additional setup after loading the view.
}
#pragma mark --subView
- (void)configSubView{
    __weak typeof(self) weakSelf =  self;
    UIView * footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 200)];
    footer.backgroundColor = [UIColor whiteColor];
    
    self.baoyouButton = [[STButton alloc] initWithFrame:CGRectMake(self.insetX, 0, 300, 44)
                                                 title:@"是否需要包邮"
                                            titleColor:KL_firstTextColor
                                             titleFont:14
                                          cornerRadius:0
                                       backgroundColor:nil
                                       backgroundImage:nil
                                                 image:[UIImage imageNamed:@"购物未选中"]];
    self.baoyouButton.selected = self.goodModel.is_bao;
    [self.baoyouButton setImage:[UIImage imageNamed:@"购物选中"] forState:UIControlStateSelected];
    self.baoyouButton.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    [self.baoyouButton setClicAction:^(UIButton *sender) {
        sender.selected = !sender.selected;

    }];
    [footer addSubview:self.baoyouButton];
    
    
    self.tejiaButton = [[STButton alloc] initWithFrame:CGRectMake(self.insetX, self.baoyouButton.bottom, 300, 44)
                                                 title:@"是否需要特价折扣"
                                            titleColor:KL_firstTextColor
                                             titleFont:14
                                          cornerRadius:0
                                       backgroundColor:nil
                                       backgroundImage:nil
                                                 image:[UIImage imageNamed:@"购物未选中"]];
    self.tejiaButton.selected = self.goodModel.is_bargain;
    [self.tejiaButton setImage:[UIImage imageNamed:@"购物选中"] forState:UIControlStateSelected];
    self.tejiaButton.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    [self.tejiaButton setClicAction:^(UIButton *sender) {
        sender.selected = !sender.selected;
        [weakSelf onSelctedTejiaButton];
    }];
    [footer addSubview:self.tejiaButton];
    
    NSString * begin = self.goodModel.bargain_statr_time;
    if (begin.length <2) {
        begin = @"9:00";
    }
    NSString * end = self.goodModel.bargain_end_time;
    if (end.length<2) {
        end = @"18:00";
    }
    self.tejiaBeginButton = [[STButton alloc] initWithFrame:CGRectMake(self.insetX, self.tejiaButton.bottom, 250, 44)
                                                      title:[NSString stringWithFormat:@"选择特价开始时间:    %@",begin]
                                                 titleColor:KL_secendTextColor
                                                  titleFont:12
                                               cornerRadius:0
                                            backgroundColor:nil
                                            backgroundImage:nil
                                                      image:nil];
    [self.tejiaBeginButton setAttributedTitle:[self.tejiaBeginButton.currentTitle
                                               st_convertAttributeStringWithKeyWord:@"选择特价开始时间:"
                                               attributes:@{NSForegroundColorAttributeName:KL_firstTextColor,NSFontAttributeName:[UIFont systemFontOfSize:14]}] forState:UIControlStateNormal];
    [self.tejiaBeginButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelctedTejiaBeiginButton];
    }];
    [self.tejiaBeginButton st_setBorderWith:1 borderColor:KL_BlueBackGroundColor cornerRadius:5];
    [footer addSubview:self.tejiaBeginButton];
    
    self.tejiaEndButton = [[STButton alloc] initWithFrame:CGRectMake(self.insetX, self.tejiaBeginButton.bottom, 250, 44)
                                                    title:[NSString stringWithFormat:@"选择特价结束时间:    %@",end]
                                               titleColor:KL_secendTextColor
                                                titleFont:12
                                             cornerRadius:0
                                          backgroundColor:nil
                                          backgroundImage:nil
                                                    image:nil];
    [self.tejiaEndButton setAttributedTitle:[self.tejiaEndButton.currentTitle
                                             st_convertAttributeStringWithKeyWord:@"选择特价结束时间:"
                                             attributes:@{NSForegroundColorAttributeName:KL_firstTextColor,NSFontAttributeName:[UIFont systemFontOfSize:14]}] forState:UIControlStateNormal];
    [self.tejiaEndButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelctedTejiaEndButton];
    }];
    [self.tejiaEndButton st_setBorderWith:1 borderColor:KL_BlueBackGroundColor cornerRadius:5];
    [footer addSubview:self.tejiaEndButton];
    
    _tejiaZheKouButton = [[STButton alloc] initWithFrame:CGRectMake(self.insetX, self.tejiaEndButton.bottom, 300, 44)
                                                   title:[NSString stringWithFormat:@"特价折扣率:    %@折",
                                                          self.zhekoulv]
                                              titleColor:KL_secendTextColor
                                               titleFont:12
                                            cornerRadius:0
                                         backgroundColor:nil
                                         backgroundImage:nil
                                                   image:nil];
    
    [_tejiaZheKouButton setAttributedTitle:[_tejiaZheKouButton.currentTitle
                                            st_convertAttributeStringWithKeyWord:@"特价折扣率:"
                                            attributes:@{NSForegroundColorAttributeName:KL_firstTextColor,NSFontAttributeName:[UIFont systemFontOfSize:14]}] forState:UIControlStateNormal];
    [_tejiaZheKouButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelctedTejiaZhekouButton];
    }];
    [footer addSubview:_tejiaZheKouButton];
    
    
    //封面
    NSArray * array = self.goodModel.cover_map;
    NSMutableArray * bannerArray = [NSMutableArray new];
    
    for (NSString *url in array) {
        STUrlPhotoModel * model = [STUrlPhotoModel new];
        model.thumbImageUrl = url;
        [bannerArray addObject:model];
    }
    self.bannerScrollView = [[KLImageScrollView alloc] initWithFrame:CGRectMake(15, _tejiaZheKouButton.bottom + 10, UIScreenWidth - 30, 120)];
    self.bannerScrollView.title = @"上传封面图片:(提示，至少上传三张图片)";
    self.bannerScrollView.delegate = self;
    self.bannerScrollView.dataSouce = bannerArray;
    self.imageUrlsArray = self.bannerScrollView.urlArray;
    [footer addSubview:self.bannerScrollView];
    //封面
    
    NSArray * detailarray = self.goodModel.synopsis;
    NSMutableArray * detailDataSouce = [NSMutableArray new];
    
    for (NSString *url in detailarray) {
        STUrlPhotoModel * model = [STUrlPhotoModel new];
        model.thumbImageUrl = url;
        [detailDataSouce addObject:model];
    }
    self.detailScrollView = [[KLImageScrollView alloc] initWithFrame:CGRectMake(15, self.bannerScrollView.bottom + 10, UIScreenWidth - 30, 120)];
    self.detailScrollView.title = @"上传详细图片:(提示，至少上传三张图片)";
    self.detailScrollView.delegate = self;
    self.detailScrollView.dataSouce = detailDataSouce;
    self.detailImageUrlsArray = self.detailScrollView.urlArray;
    [footer addSubview:self.detailScrollView];
    
    
    STButton * confimButton = [[STButton alloc] initWithFrame:CGRectMake(30, self.detailScrollView.bottom + 30, UIScreenWidth - 60, 44)
                                                        title:@"确认发布"
                                                   titleColor:[UIColor whiteColor]
                                                    titleFont:18
                                                 cornerRadius:5
                                              backgroundColor:KL_BlueBackGroundColor
                                              backgroundImage:nil
                                                        image:nil];
    [confimButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelectedCommitButton];
    }];
    confimButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [footer addSubview:confimButton];
    
    self.tableView.tableFooterView = footer;
    footer.height = confimButton.bottom + 20;
    self.tableView.tableFooterView = footer;
}
- (void)configDataSouce{
    
    NSString * area = [NSString stringWithFormat:@"%@%@",
                       [STLocationManger defult].lastProvence.length?[STLocationManger defult].lastProvence:@"",
                       [STLocationManger defult].lastCity.length? [STLocationManger defult].lastCity:@"定位失败"];
    if (self.goodModel.address.length) {
        area = self.goodModel.address;
    }
    self.datasouce = @[
                       [[STTableEasyModel alloc] initWithTextString:@"区域:"
                                                       detailString:area],
                       [[STTableEasyModel alloc] initWithTextString:@"商品库存:"
                                                       detailString:self.goodModel.stock.description],
                       [[STTableEasyModel alloc] initWithTextString:@"标题:"
                                                       detailString:self.goodModel.goods_name],
                       [[STTableEasyModel alloc] initWithTextString:@"描述:"
                                                       detailString:self.goodModel.abstract],
                       [[STTableEasyModel alloc] initWithTextString:@"价格:"
                                                       detailString:self.goodModel.price]
                       ];
    NSMutableArray * array = [self.datasouce mutableCopy];
    self.datasouce = array;
    [self.tableView reloadData];
}
#pragma --mark UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.datasouce.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return self.datasouce[indexPath.row].height;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 10;
}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [UIView new];
}
- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * reuseIdentifier =  @"cell";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuseIdentifier];
        
    }
    cell.textLabel.textColor = UIColorFromRGBA(0x333333);
    cell.textLabel.font = [UIFont systemFontOfSize:14];
    cell.detailTextLabel.font = [UIFont systemFontOfSize:13];
    cell.detailTextLabel.textColor = UIColorFromRGBA(0x999999);
    STTableEasyModel * model = self.datasouce[indexPath.row];
    
    cell.textLabel.text = model.textString;
    cell.detailTextLabel.text = model.detailString;
    if (model.accessoryView) {
        cell.accessoryView = model.accessoryView;
    }else{
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    
    return cell;
}
#pragma --mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    STTableEasyModel * model = self.datasouce[indexPath.row];
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
    if (indexPath.row == 0) {
        [self onSlectedAddCellWithIndexPath:indexPath model:model];
        return;
    }
    //公用点击
    if (!model.accessoryView) {
        NSString * str = [model.textString stringByReplacingOccurrencesOfString:@":" withString:@""];
        NSString * palceHolder = [NSString stringWithFormat:@"请输入%@",str];
        palceHolder = [palceHolder stringByReplacingOccurrencesOfString:@":" withString:@""];
        NSString * title = model.textString;
        title = [title stringByReplacingOccurrencesOfString:@":" withString:@""];
        STTableViewDetailController * vc = [[STTableViewDetailController alloc] initWithPlaceholder:palceHolder title:title  complete:^(NSString *text, STTableViewDetailController *detailControllerVC) {
            model.detailString = text;
            [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
            [self.navigationController popViewControllerAnimated:YES];
            
        }];
        vc.maxTextNum = 1000;
        if (indexPath.row == 4 || indexPath.row == 1 ) {
            vc.textFiled.keyboardType = UIKeyboardTypeDecimalPad;
        }
        vc.textFiled.text = model.detailString;
        [self.navigationController pushViewController:vc animated:YES];
    }
    
    //酒店
    
}
#pragma mark --Private Method
- (NSArray*)hourArray{
    NSMutableArray * array = [NSMutableArray new];
    for (int i = 0; i < 24; i ++) {
        NSString * hour = @(i).description;
        if (i < 10) {
            hour = [NSString stringWithFormat:@"0%@",hour];
        }
        [array addObject:hour];
    }
    return array;
}
- (NSArray*)minteArray{
    NSMutableArray * array = [NSMutableArray new];
    for (int i = 0; i < 60; i ++) {
        NSString * min = @(i).description;
        if (i < 10) {
            min = [NSString stringWithFormat:@"0%@",min];
        }
        [array addObject:min];
    }
    return array;
}
- (NSArray*)zhekouArray{
    NSMutableArray * array = [NSMutableArray new];
    for (int i = 1; i < 10; i ++) {
        NSString * zhekou = @(i).description;
        
        zhekou = [NSString stringWithFormat:@"%@折",zhekou];
        
        [array addObject:zhekou];
    }
    return array;
}
#pragma mark --KLImageScrollViewDelegate
- (void)klimageScrollView:(KLImageScrollView *)imageScrollView didSendImageUrls:(NSArray *)array{
    [self onSelectedCommitButton];
}
#pragma mark --action Method
- (void)onSlectedAddCellWithIndexPath:(NSIndexPath*)indexPath model:(STTableEasyModel*)model{
    STPickerViewController * pickerVc  = [[STPickerViewController alloc] initWithDefualtAreaPickerWithHandle:^(NSString *finshString, NSString *area, NSString *city, NSString *provence) {
        model.detailString = [NSString stringWithFormat:@"%@%@",provence,city];
        [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }];
    [self presentViewController:pickerVc animated:NO completion:nil];
}
- (void)onSelctedTejiaButton{
    
}
- (void)onSelctedTejiaBeiginButton{
    STPickerViewController * picker = [[STPickerViewController alloc] initWithPickerArray:@[[self hourArray],[self minteArray]] andWithHandle:^(NSArray<NSString *> *stringArray) {
        NSString * title = [NSString stringWithFormat:@"%@:%@",stringArray.firstObject,stringArray.lastObject];
        [self.tejiaBeginButton setTitle:[NSString stringWithFormat:@"选择特价开始时间:     %@",title] forState:UIControlStateNormal];
        [self.tejiaBeginButton setAttributedTitle:[self.tejiaBeginButton.currentTitle
                                                   st_convertAttributeStringWithKeyWord:@"选择特价开始时间:"
                                                   attributes:@{NSForegroundColorAttributeName:KL_firstTextColor,NSFontAttributeName:[UIFont systemFontOfSize:14]}] forState:UIControlStateNormal];
    }];
    [self presentViewController:picker animated:YES completion:nil];
}
- (void)onSelctedTejiaEndButton{
    STPickerViewController * picker = [[STPickerViewController alloc] initWithPickerArray:@[[self hourArray],[self minteArray]] andWithHandle:^(NSArray<NSString *> *stringArray) {
        NSString * title = [NSString stringWithFormat:@"%@:%@",stringArray.firstObject,stringArray.lastObject];
        [self.tejiaEndButton setTitle:[NSString stringWithFormat:@"选择特价结束时间:     %@",title] forState:UIControlStateNormal];
        [self.tejiaEndButton setAttributedTitle:[self.tejiaEndButton.currentTitle
                                                 st_convertAttributeStringWithKeyWord:@"选择特价结束时间:"
                                                 attributes:@{NSForegroundColorAttributeName:KL_firstTextColor,NSFontAttributeName:[UIFont systemFontOfSize:14]}] forState:UIControlStateNormal];
    }];
    [self presentViewController:picker animated:YES completion:nil];
}
- (void)onSelctedTejiaZhekouButton{
    STPickerViewController * picker = [[STPickerViewController alloc] initWithPickerArray:@[[self zhekouArray]] andWithHandle:^(NSArray<NSString *> *stringArray) {
        NSString * title = [NSString stringWithFormat:@"%@",stringArray.firstObject];
        self.zhekoulv = [title substringToIndex:1];
        [_tejiaZheKouButton setTitle:[NSString stringWithFormat:@"特价折扣率:     %@",title] forState:UIControlStateNormal];
        [_tejiaZheKouButton setAttributedTitle:[_tejiaZheKouButton.currentTitle
                                                st_convertAttributeStringWithKeyWord:@"特价折扣率:"
                                                attributes:@{NSForegroundColorAttributeName:KL_firstTextColor,NSFontAttributeName:[UIFont systemFontOfSize:14]}] forState:UIControlStateNormal];
    }];
    [self presentViewController:picker animated:YES completion:nil];
}

- (void)onSelectedCommitButton{
    
    for (STTableEasyModel * model in self.datasouce) {
        if ([model.detailString isEqualToString:@"定位失败"] &&
            [model.textString isEqualToString:@"区域"]) {
            [SVProgressHUD showErrorWithStatus:@"请选择区域"];
            return;
        }else{
            if (!model.detailString.length && !model.accessoryView) {
                NSString * str = [NSString stringWithFormat:@"请输入%@",model.textString];
                [SVProgressHUD showErrorWithStatus:str];
                return;
            }
        }
    }
    
    if (self.bannerScrollView.dataSouce.count < 3) {
        [SVProgressHUD showErrorWithStatus:@"至少三张封面图图片"];
        return;
    }
    if (self.detailScrollView.dataSouce.count < 3) {
        [SVProgressHUD showErrorWithStatus:@"至少三张详细图片"];
        return;
    }
    
    [SVProgressHUD showWithStatus:@"请稍后"];
    if (self.bannerScrollView.isSendAll && self.detailScrollView.isSendAll) {
        self.imageUrlsArray = self.bannerScrollView.urlArray;
        self.detailImageUrlsArray = self.detailScrollView.urlArray;
        if (!self.goodModel) {
            [self senduploadGoodRequest];
        }else{
            [self sendChangeGoodRequest];
        }
        
    }else{
        if (!self.bannerScrollView.isSendAll) {
            [self.bannerScrollView sendImageToQiNiu];
        }
        if (!self.detailScrollView.isSendAll) {
            [self.detailScrollView sendImageToQiNiu];
        }
        
    }
    
}
- (void)senduploadGoodRequest{
    
    NSMutableDictionary * dic = [NSMutableDictionary new];
    NSString * url = [NSString stringWithFormat:@"%@%@%@",serviceUrl,@"/api/shop/addgoods",[NSString stringWithFormat:@"?token=%@",[STUserManger defult].token]];
    
    NSArray * paras = @[@"address",@"stock",@"goods_name",@"abstract",@"price"];
    for (int i = 0; i <paras.count; i ++) {
        STTableEasyModel * model = self.datasouce[i];
        NSString * key = paras[i];
        if (key.length > 1 && model.detailString.length) {
            [dic setObject:model.detailString forKey:key];
        }
    }
    //旅游住宿增加
    if ([self.datasouce.lastObject.textString containsString:@"详细地址"]) {
        NSString * area = self.datasouce.firstObject.detailString;;
        NSString * detail = self.datasouce.lastObject.detailString;
        NSString * address = [NSString stringWithFormat:@"%@%@",area,detail];
        [dic setObject:address forKey:@"address"];
    }
    if (self.numPeopleTextFiled.textFiled.text.length) {
        NSString * ads = [NSString stringWithFormat:@"入住人数最多%@人",self.numPeopleTextFiled.textFiled.text];
        NSString * originabs = dic[@"abstract"];
        [dic removeObjectForKey:@"abstract"];
        NSString * finsh = [NSString stringWithFormat:@"%@  %@",originabs,ads];
        [dic setObject:finsh forKey:@"abstract"];
    }
    for (STTableEasyModel * model in self.datasouce) {
        if ([model.textString containsString:@"联系电话"]) {
            [dic setObject:model.detailString forKey:@"telephone"];
            break;
        }
    }
    //出售方式，固定价格
    [dic setObject:@"1" forKey:@"sale_type"];
    //是否特价
    [dic setObject:@(self.tejiaButton.selected) forKey:@"is_bargain"];
    if (self.tejiaButton.selected) {
        NSString * beigin = [self.tejiaBeginButton.currentTitle stringByReplacingOccurrencesOfString:@"选择特价开始时间:" withString:@""];
        beigin = [beigin stringByReplacingOccurrencesOfString:@" " withString:@""];
        [dic setObject:beigin forKey:@"bargain_statr_time"];
        
        NSString * end = [self.tejiaEndButton.currentTitle stringByReplacingOccurrencesOfString:@"选择特价结束时间:" withString:@""];
        end = [end stringByReplacingOccurrencesOfString:@" " withString:@""];
        [dic setObject:end forKey:@"bargain_end_time"];
        
        NSInteger  num = [self.zhekoulv integerValue];
        [dic setObject:@(num*10) forKey:@"bargain_price"];
        
    }
    //图片
    NSString * cover_map = [self.imageUrlsArray componentsJoinedByString:@","];
    [dic setObject:cover_map forKey:@"cover_map"];
    NSString * synopsis = [self.detailImageUrlsArray componentsJoinedByString:@","];
    [dic setObject:synopsis forKey:@"synopsis"];
    //分类
    [dic setObject:self.model.typeId.description forKey:@"classification"];
    [dic setObject:@(self.baoyouButton.selected) forKey:@"is_bao"];
    [[STNetWrokManger defaultClient] requestWithPath:url
                                              method:STHttpRequestTypePost
                                          parameters:dic
                                             success:^(NSURLSessionDataTask *operation, id responseObject) {
                                                 [SVProgressHUD dismiss];
                                                 NSNumber * num = responseObject[@"data"][@"leave"];
                                                 [SVProgressHUD showSuccessWithStatus:[NSString stringWithFormat:@"上传商品成功,您还可以发布%@个该类型的商品",@(num.integerValue-1)]];
                                                 [self.navigationController popViewControllerAnimated:YES];
                                                 
                                             } failure:^(NSString *stateCode, STError *error) {
                                                 [SVProgressHUD dismiss];
                                                 [SVProgressHUD showErrorWithStatus:error.desc];
                                                 
                                             }];
}
- (void)sendChangeGoodRequest{
    NSMutableDictionary * dic = [NSMutableDictionary new];
    NSString * url = [NSString stringWithFormat:@"%@%@%@",serviceUrl,@"/api/shop/eidtgoods",[NSString stringWithFormat:@"?token=%@",[STUserManger defult].token]];
    
    NSArray * paras = @[@"address",@"stock",@"goods_name",@"abstract",@"price"];
    for (int i = 0; i <paras.count; i ++) {
        STTableEasyModel * model = self.datasouce[i];
        NSString * key = paras[i];
        if (key.length > 1 && model.detailString.length) {
            [dic setObject:model.detailString forKey:key];
        }
    }
    for (STTableEasyModel * model in self.datasouce) {
        if ([model.textString containsString:@"联系电话"]) {
            [dic setObject:model.detailString forKey:@"telephone"];
            break;
        }
    }
    
    //出售方式，固定价格
    [dic setObject:@"1" forKey:@"sale_type"];
    //是否特价
    
    //是否特价
    [dic setObject:@(self.tejiaButton.selected) forKey:@"is_bargain"];
    //是否包邮
    [dic setObject:@(self.baoyouButton.selected) forKey:@"is_bao"];
    if (self.tejiaButton.selected) {
        NSString * beigin = [self.tejiaBeginButton.currentTitle stringByReplacingOccurrencesOfString:@"选择特价开始时间:" withString:@""];
        beigin = [beigin stringByReplacingOccurrencesOfString:@" " withString:@""];
        [dic setObject:beigin forKey:@"bargain_statr_time"];
        
        NSString * end = [self.tejiaEndButton.currentTitle stringByReplacingOccurrencesOfString:@"选择特价结束时间:" withString:@""];
        end = [end stringByReplacingOccurrencesOfString:@" " withString:@""];
        [dic setObject:end forKey:@"bargain_end_time"];
        
        NSInteger  num = [self.zhekoulv integerValue];
        [dic setObject:@(num*10) forKey:@"bargain_price"];
        
    }
    //图片
    NSString * cover_map = [self.imageUrlsArray componentsJoinedByString:@","];
    [dic setObject:cover_map forKey:@"cover_map"];
    NSString * synopsis = [self.detailImageUrlsArray componentsJoinedByString:@","];
    [dic setObject:synopsis forKey:@"synopsis"];
    if (self.goodModel) {
        [dic setObject:self.goodModel.goodID forKey:@"goods_id"];
    }
    //分类
    [dic setObject:self.goodModel.classification forKey:@"classification"];
    [[STNetWrokManger defaultClient] requestWithPath:url
                                              method:STHttpRequestTypePost
                                          parameters:dic
                                             success:^(NSURLSessionDataTask *operation, id responseObject) {
                                                 [SVProgressHUD dismiss];
                                                 [SVProgressHUD showSuccessWithStatus:@"修改商品成功"];
                                                 [self.navigationController popViewControllerAnimated:YES];
                                                 
                                             } failure:^(NSString *stateCode, STError *error) {
                                                 [SVProgressHUD dismiss];
                                                 [SVProgressHUD showErrorWithStatus:error.desc];
                                                 
                                             }];
}
@end



